<?php

class RecvMessageAction extends CAction
{

	public function run()
	{
        $userMessageId=(int)Yii::app()->user->getState('lastUserMessageID');
        $guildMessageId=(int)Yii::app()->user->getState('lastGuildMessageID');
        $curTime=time() ;
        $userId=0 ;
        $guildId=0 ;

        $userMessageList=UserMessage::model()->findAll('destId=:destId and id>:id and createTime>:createTime-600',
                array(':destId'=>$userId,':id'=>$userMessageId,':createTime'=>$curTime) ) ;

        if ( !empty($userMessageList) )
        {
            $userMessageId=$userMessageList[count($userMessageList)-1]->id ;
            Yii::app()->user->setState('lastUserMessageID',$userMessageId);
        }

        $guildMessageList=GuildMessage::model()->findAll('guildId=:guildId and id>:id and createTime>:createTime-600',
                array(':guildId'=>$guildId,':id'=>$guildMessageId,':createTime'=>$curTime) ) ;

        if ( !empty($guildMessageList) )
        {
            $guildMessageId=$guildMessageList[count($guildMessageList)-1]->id ;
            Yii::app()->user->setState('lastGuildMessageID',$guildMessageId);
        }

        $this->controller->render('RecvMessage',
                array('userMessageList'=>$userMessageList,'guildMessageList'=>$guildMessageList));


	}
}

?>
